/*
 * @author <a href="http://jheer.org">jeffrey heer</a>
 */

package groovy.prefuse.impl.action;

import java.util.Iterator;

import prefuse.*
import prefuse.data.*
import prefuse.action.*
import prefuse.data.tuple.*

/**
 * Switch the root of the tree by requesting a new spanning tree
 * at the desired root
 */
public class TreeRootAction extends GroupAction {

	public TreeRootAction()
	{
		super()
	}

	public TreeRootAction(String graphGroup)
	{
		super(graphGroup)
	}
	
	public TreeRootAction(Visualization v, String graphGroup) {
		super(v, graphGroup)
	}


	public void run(double frac) {
		TupleSet focus = m_vis.getGroup(Visualization.FOCUS_ITEMS);
		if ( focus==null || focus.getTupleCount() == 0 ) return;
		
		Graph g = (Graph)m_vis.getGroup(m_group);
		Node f = null;
		Iterator tuples = focus.tuples();
		while (tuples.hasNext() && !g.containsTuple(f=(Node)tuples.next()))
		{
		    f = null;
		}
		if ( f == null ) return;
		g.getSpanningTree(f);
	}
}